//package com.ly.mpayment.rest.system.slow;
//
//import com.ly.mpayment.core.util.*;
//import com.ly.mpayment.persist.entity.slow.SlowOrder;
//import com.ly.mpayment.persist.service.slow.SlowOrderService;
//import com.ly.mpayment.persist.service.user.IUserService;
//import com.ly.mpayment.rest.AbsRest;
//import net.sf.json.JSONObject;
//import org.apache.log4j.Logger;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//import org.springframework.web.bind.annotation.RequestBody;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.ws.rs.POST;
//import javax.ws.rs.Path;
//import javax.ws.rs.core.Context;
//import java.io.*;
//import java.util.Map;
//
//@Component
//@Path("system/sloworder")
//public class SlowOrderRest extends AbsRest {
//	Logger logger = Logger.getLogger(SlowOrderRest.class);
//	@Autowired
//	IUserService userService;
////	@Autowired
////	SlowOrderService slowOrderService;
//
//	@SuppressWarnings("static-access")
//	@POST
//	@Path("findPageSlowOrder")
//	public String findPageSlowOrder(String data,@Context HttpServletRequest request){
//		String result = this.validationParameter(data, request, userService, "phoneNum","operators","province",
//				"city","price","importTime","start","pageSize","isLock","rechargeState","wxOrder","endtime","payState");
//		if(result == null){
//			JSONObject json = JsonUtils.getJSONOBJCT().fromObject(data);
//			Map<String, Object> parameters = MapUtil.getMap();
//			if(!StringUtils.isBlank(json.getString("phoneNum"))){
//				parameters.put(":phoneNum", json.getString("phoneNum"));
//			}
//			if(!StringUtils.isBlank(json.getString("operators"))){
//				parameters.put(":operators", json.getString("operators"));
//			}
//			if(!StringUtils.isBlank(json.getString("rechargeState"))){
//				parameters.put(":rechargeState", json.getInt("rechargeState"));
//			}
//			if(!StringUtils.isBlank(json.getString("province"))){
//				parameters.put(":province", json.getString("province"));
//			}
//			if(!StringUtils.isBlank(json.getString("city"))){
//				parameters.put(":city", json.getString("city"));
//			}
//			if(!StringUtils.isBlank(json.getString("price"))){
//				parameters.put(":price", json.getString("price"));
//			}
//			if(!StringUtils.isBlank(json.getString("importTime"))){
//				parameters.put(":importTime", (json.getString("importTime")));
//			}
//			if(!StringUtils.isBlank(json.getString("endtime"))){
//				parameters.put(":endtime", (json.getString("endtime")));
//			}
//			if(!StringUtils.isBlank(json.getString("isLock"))){
//				parameters.put(":isLock", json.getInt("isLock"));
//			}
//			if(!StringUtils.isBlank(json.getString("wxOrder"))){
//				parameters.put(":wxOrder", json.getInt("wxOrder"));
//			}
//			if(!StringUtils.isBlank(json.getString("payState"))){
//				parameters.put(":payState", json.getInt("payState"));
//			}
//			if(!StringUtils.isBlank(json.getString("payState"))){
//				parameters.put(":payState", json.getInt("payState"));
//			}
//
//			return ResultMessage.getSucceed(JsonUtils.excludes(this.slowOrderService.findPageSlowOrder(parameters, json.getInt("start"), json.getInt("pageSize")),
//					new String[]{"","","","","","","","",""}));
//		}
//		return result;
//	}
//
//	/**
//	 * 骑士卡下单
//	 * @param data
//	 * @param request
//	 * @return
//	 */
//	@Path("commitSlowOrder")
//	@POST
//	public String commitSlowOrder(@RequestBody String data, @Context HttpServletRequest request){
//		if(StringUtils.isBlank(data)){
//			return ResultMessage.getFailt("参数错误");
//		}
//		SlowOrder slowOrder = this.slowOrderService.commitSlowOrder(data);
//		if(!StringUtils.isBlank(slowOrder.getRemark())){
//			com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
//			json.put("h5PayUrl",slowOrder.getRemark());
//			json.put("orderId",slowOrder.getOrderuuid());
//			json.put("payState",slowOrder.getPayState());
//			json.put("payType",slowOrder.getPayType());
//			return ResultMessage.getSucceed(json.toString());
//		}
//		return ResultMessage.getFailt("下单失败");
//
//	}
//
//	@Path("queryOrder")
//	@POST
//	public String queryOrder(@RequestBody String data, @Context HttpServletRequest request){
//		if(StringUtils.isBlank(data)){
//			return ResultMessage.getFailt("参数错误");
//		}
//		SlowOrder slowOrder = this.slowOrderService.queryOrder(data);
//		//微信支付状态 1支付中 2支付成功 3支付失败
//		if(slowOrder != null ){
//			com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
//			json.put("payState",slowOrder.getPayState());
//			return ResultMessage.getSucceed(json.toString());
//		}
//		return ResultMessage.getFailt("查询失败");
//
//	}
//
////	/**
////	 * 删除
////	 * @param data
////	 * @param request
////	 * @return
////	 */
////	@SuppressWarnings("static-access")
////	@POST
////	@Path("deleteSlowOrder")
////	public String deleteSlowOrder(String data,@Context HttpServletRequest request){
////		String result = this.validationParameter(data, request, userService, "orderuuid");
////		if(result == null ){
////			JSONObject json = JsonUtils.getJSONOBJCT().fromObject(data);
////			WeiXinOrder order = this.wxOrderService.findById(json.getString("orderuuid"));
////			if(order != null && order.getIsLock() == 0){
////				if(this.wxOrderService.deleteWeiXinOrder(json.getString("orderuuid"))){
////					return ResultMessage.getSucceed(null);
////				}
////				return ResultMessage.getFailt(null);
////			}else{
////				return ResultMessage.getFailt(null, "订单已经锁定不能删除");
////			}
////
////		}
////		return result;
////	}
//
//	@SuppressWarnings("static-access")
//	@POST
//	@Path("updateOrderState")
//	public String updateOrderState(String data,@Context HttpServletRequest request){
//		String result = this.validationParameter(data, request, userService, "orderuuid","rechargeState");
//		if(result == null ){
//			JSONObject json = JsonUtils.getJSONOBJCT().fromObject(data);
//			SlowOrder order = this.slowOrderService.findById(json.getString("orderuuid"));
//			if(order != null ){
//				order.setRechargeState(json.getInt("rechargeState"));
//				if(this.slowOrderService.updateSlowOrder(order)){
//					return ResultMessage.getSucceed(null);
//				}
//				return ResultMessage.getFailt("");
//			}else{
//				return ResultMessage.getFailt("订单已经锁定");
//			}
//
//		}
//		return result;
//	}
//
////	@SuppressWarnings("static-access")
////	@POST
////	@Path("exportSlowOrder")
////	public String exportSlowOrder(String data, @Context HttpServletRequest request) {
////		String result = this.validationParameter(data, request, userService, "phoneNum","operators","province",
////				"city","price","importTime","isLock","rechargeState","wxOrder","endtime","payState");
////		if(result == null){
////			JSONObject json = JsonUtils.getJSONOBJCT().fromObject(data);
////			Map<String, Object> parameters = MapUtil.getMap();
////			if(!StringUtils.isBlank(json.getString("phoneNum"))){
////				parameters.put(":phoneNum", json.getString("phoneNum"));
////			}
////			if(!StringUtils.isBlank(json.getString("operators"))){
////				parameters.put(":operators", json.getString("operators"));
////			}
////			if(!StringUtils.isBlank(json.getString("rechargeState"))){
////				parameters.put(":rechargeState", json.getInt("rechargeState"));
////			}
////			if(!StringUtils.isBlank(json.getString("province"))){
////				parameters.put(":province", json.getString("province"));
////			}
////			if(!StringUtils.isBlank(json.getString("city"))){
////				parameters.put(":city", json.getString("city"));
////			}
////			if(!StringUtils.isBlank(json.getString("price"))){
////				parameters.put(":price", json.getString("price"));
////			}
////			if(!StringUtils.isBlank(json.getString("importTime"))){
////				parameters.put(":importTime", (json.getString("importTime")));
////			}
////			if(!StringUtils.isBlank(json.getString("endtime"))){
////				parameters.put(":endtime", (json.getString("endtime")));
////			}
////
////			if(!StringUtils.isBlank(json.getString("isLock"))){
////				parameters.put(":isLock", json.getInt("isLock"));
////			}
////			if(!StringUtils.isBlank(json.getString("wxOrder"))){
////				parameters.put(":wxOrder", json.getInt("wxOrder"));
////			}
////			if(!StringUtils.isBlank(json.getString("payState"))){
////				parameters.put(":payState", json.getInt("payState"));
////			}
////
////
////			JSONObject obj = JsonUtils.getJSONOBJCT();
////			String exportResult = ExportExcelUtil.exportWxOrder(this.slowOrderService, parameters);
////			logger.info("exportResult:" + exportResult);
////			if (exportResult != null) {
////				obj.put("path", CookieRedis.get("download").concat(File.separator)
////						+ exportResult.replace( CookieRedis.get("exportPath"), ""));
////				return ResultMessage.getSucceed( obj.toString());
////			} else {
////				return ResultMessage.getFailt("失败");
////			}
////		}
////		return result;
////	}
////
////	@POST
//////	@Path("importSlowOrder")
//////	@Produces(MediaType.APPLICATION_JSON)
//////	@Consumes(MediaType.MULTIPART_FORM_DATA)
//////	public synchronized String importSlowOrder(FormDataMultiPart form, @Context HttpServletRequest request) {
//////		// String result = this.validationParameterToken(request, userService);
//////		// if(result == null){
//////		Map<String, List<FormDataBodyPart>> lists = form.getFields();
//////		if (!lists.isEmpty()) {
//////			File filepicF = null;
//////			try {
//////				for (String str : lists.keySet()) {
//////					String picName = FileUtils.server.getProperty("exportPath");
//////					String fileName = lists.get(str).get(0).getFormDataContentDisposition().getFileName();// (String)
//////
//////					fileName = fileName.substring(fileName.lastIndexOf("."), fileName.length());
//////
//////					fileName = new Date().getTime() + fileName;
//////
//////					filepicF = new File(picName + File.separator + fileName);
//////					InputStream inputStream = lists.get(str).get(0).getValueAs(InputStream.class);
//////					OutputStream outStream = new FileOutputStream(filepicF);
//////					IOUtils.copy(inputStream, outStream);
//////					outStream.close();
//////
//////					// 判断是否为excel类型文件
//////					if (!fileName.endsWith(".xls") && !fileName.endsWith(".xlsx")) {
//////						return ResultMessage.getFailt(null, "文件类型不是excel类型!");
//////					}
//////
//////					InputStream fis = null;
//////					Workbook wookbook = null;
//////
//////					try {
//////						// 获取一个绝对地址的流
//////						fis = new FileInputStream(filepicF.getAbsolutePath());
//////					} catch (Exception e) {
//////						e.printStackTrace();
//////						return ResultMessage.getFailt(null);
//////					}
//////
//////					try {
//////						// 2003版本的excel，用.xls结尾
//////						wookbook = new HSSFWorkbook(fis);// 得到工作簿
//////					} catch (Exception ex) {
//////						// ex.printStackTrace();
//////						try {
//////							// 2007版本的excel，用.xlsx结尾
//////							fis = new FileInputStream(filepicF.getAbsolutePath());
//////							wookbook = new XSSFWorkbook(fis);// 得到工作簿
//////						} catch (IOException e) {
//////							// TODO Auto-generated catch block
//////							e.printStackTrace();
//////							return ResultMessage.getFailt(null);
//////						}
//////					}
//////
//////					// 得到一个工作表
//////					Sheet sheet = wookbook.getSheetAt(0);
//////					// 获得表头
//////					Row rowHead = sheet.getRow(0);
//////					// 判断表头是否正确
//////					if (rowHead.getPhysicalNumberOfCells() != 4) {
//////						return ResultMessage.getFailt(null, "表头的数量不对!");
//////					}
//////					// 获得数据的总行数
//////					int totalRowNum = sheet.getLastRowNum();
//////					List<WeiXinOrder> orders = new ArrayList<WeiXinOrder>();
//////					//获取是否合并开关
//////					// 获得所有数据
//////					for (int i = 1; i <= totalRowNum; i++) {
//////						WeiXinOrder order = new WeiXinOrder();
//////						// 获得第i行对象 电话 支付金额 充值结果，微信支付单号
//////						Row row = sheet.getRow(i);
//////						if(row != null && row.getCell(0) != null && row.getCell(1) != null && row.getCell(2) != null && row.getCell(3) != null){
//////							row.getCell(0).setCellType(Cell.CELL_TYPE_STRING);
//////							row.getCell(1).setCellType(Cell.CELL_TYPE_STRING);
//////							row.getCell(2).setCellType(Cell.CELL_TYPE_STRING);
//////							row.getCell(3).setCellType(Cell.CELL_TYPE_STRING);
//////							order.setPhoneNum(row.getCell(0) == null  || row.getCell(0).equals("")  ? null : row.getCell(0).getStringCellValue().toString().trim());
//////							order.setPrice(row.getCell(1) == null || row.getCell(1).equals("")  ? BigDecimal.ZERO  : BigUtil.getBigDecimal(row.getCell(1).getStringCellValue()));
//////							order.setRechargeState(row.getCell(2) == null || row.getCell(1).equals("2")   ? 1 : row.getCell(2).getStringCellValue().equals("充值成功") ? 2 : row.getCell(2).getStringCellValue().equals("充值失败") ? 3 : 5);
//////							order.setWxOrder(row.getCell(3) == null  || row.getCell(3).equals("")  ? "" : row.getCell(3).getStringCellValue().toString());
//////							orders.add(order);
//////						}else{
//////							logger.error("导出数据错误:检查到有空数据");
//////							break;
//////						}
//////					}
//////					if (!orders.isEmpty()) {
//////						if(this.wxOrderService.updateWeixinOrders(orders)){
//////							return ResultMessage.getSucceed(null);
//////						}else{
//////							return ResultMessage.getFailt(null);
//////						}
//////					}
//////				}
//////
//////			} catch (Exception e) {
//////				e.printStackTrace();
//////				return ResultMessage.getFailt(null);
//////			}
//////			return null;
//////		}
//////		return ResultMessage.getFailt(null);
//////	}
//}
